package cn.zhage.aimin.drug.service;

import cn.zhage.aimin.drug.entity.Drug;
import cn.zhage.aimin.drug.mapper.DrugMapper;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.extension.service.impl.ServiceImpl;
import lombok.RequiredArgsConstructor;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.stereotype.Service;

import java.util.List;

/**
 * <p>
 * 药品表，用于存储具体药品的信息和库存状态 服务实现类
 * </p>
 *
 * @author root
 * @since 2025/06/23
 */
@Service
@RequiredArgsConstructor
public class DrugServiceImpl extends ServiceImpl<DrugMapper, Drug> implements DrugService {

    private final DrugMapper drugMapper;

    @Override
    @Cacheable(value = "drugCache", key = "#categoryId")
    public List<Drug> findDrugByCategoryId(Integer categoryId) {
        LambdaQueryWrapper<Drug> eq = new LambdaQueryWrapper<Drug>().eq(Drug::getCategoryId, categoryId);
        return list(eq);
    }


    @Override
    public List<Drug> list() {
        return  drugMapper.list();
    }


}
